% Paper: E- Monetary Theory  (2nd edition)
% Author: Duong Ngotran
% Graph: Crisis - Large scale asset purchase

%----------------------------------------------------------------------------
% Some Parameters
%----------------------------------------------------------------------------
T = 301;    %Number of periods 
var_foc = 29;      % Number of variables in one period
pos_value = 3;     % Position of var_value in A
truc = (-1):(T-2);         % Horizontal axis when drawing with level
spline_truc = (-1):(1/4):(T-2);     %Horizontal axis when drawing with spline 
size_struc = 1201;  % size of spline truc
deltab = 0.5;

%----------------------------------------------------------------------------
% LSAP with x=0.0001
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_without_adjusting_rn_1.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_10= rf_t;
rh_10= rh_t;
rrf_10 = rrf_t;
ql_10= AP_S(mapp('ql'),:);
pie_10= AP_S(mapp('pie'),:);
y_10 = AP_S(mapp('y'),:);
gm_10 = s_growth_M;
m_10 = AP_S(mapp('m'),:);
n_10 = AP_S(mapp('n'),:);


%----------------------------------------------------------------------------
% LSAP with x=0.0002
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_without_adjusting_rn_2.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_20= rf_t;
rh_20= rh_t;
rrf_20 = rrf_t;
ql_20= AP_S(mapp('ql'),:);
pie_20= AP_S(mapp('pie'),:);
y_20 = AP_S(mapp('y'),:);
gm_20 = s_growth_M;
m_20 = AP_S(mapp('m'),:);
n_20 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
% LSAP with x=0.0004
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_without_adjusting_rn_4.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_40= rf_t;
rh_40= rh_t;
rrf_40 = rrf_t;
ql_40= AP_S(mapp('ql'),:);
pie_40= AP_S(mapp('pie'),:);
y_40 = AP_S(mapp('y'),:);
gm_40 = s_growth_M;
m_40 = AP_S(mapp('m'),:);
n_40 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
% ZLB during 80 periods
%----------------------------------------------------------------------------
filename= 'EMT_LSAP_without_adjusting_rn_8.txt';
[ rf_t, rh_t, rrf_t, AP_S, mapp, s_growth_M ] = lsap_zlb_duration( filename );
rf_80= rf_t;
rh_80= rh_t;
rrf_80 = rrf_t;
ql_80= AP_S(mapp('ql'),:);
pie_80= AP_S(mapp('pie'),:);
y_80 = AP_S(mapp('y'),:);
gm_80 = s_growth_M;
m_80 = AP_S(mapp('m'),:);
n_80 = AP_S(mapp('n'),:);

%----------------------------------------------------------------------------
%Figure
%----------------------------------------------------------------------------
set(groot, 'DefaultLegendInterpreter', 'latex')

figure('Name', 'Federal Funds Rate');
plot(truc, rf_10, truc, rf_20, truc, rf_40);
line_fewer_markers(truc, rf_80, 15, '-rs');
leg = legend('$R^f$ - $x_0$=.0001', '$R^f$ - $x_0$=.0002', '$R^f$ - $x_0$=.0004','$R^f$ - $x_0=$.0008', 'location', 'best');

figure('Name', 'Real rate of borrowing');
plot(truc, rh_10, truc, rh_20, truc, rh_40);
line_fewer_markers(truc, rh_80, 15, '-rs');
leg = legend('$r^h$ - $x_0$=.0001', '$r^h$ - $x_0$=.0002', '$r^h$ - $x_0$=.0004','$r^h$ - $x_0$=.0008', 'location', 'best');

figure('Name', 'Money Supply');
plot(spline_truc, m_10, spline_truc, m_20, spline_truc, m_40);
line_fewer_markers(spline_truc, m_80, 15, '-rs');
leg = legend('$m$ - $x_0$=.0001', '$m$ - $x_0$=.0002', '$m$ - $x_0$=.0004', '$m$ - $x_0$=.0008', 'location', 'best');

figure('Name', 'Output');
plot(spline_truc, y_10, spline_truc, y_20, spline_truc, y_40);
line_fewer_markers(spline_truc, y_80, 15, '-rs');
leg = legend('$y$ - $x_0$=.0001', '$y$ - $x_0$=.0002', '$y$ - $x_0$=.0004', '$y$ - $x_0$=.0008', 'location', 'best');

figure('Name', 'Inflation');
plot(spline_truc, pie_10, spline_truc, pie_20, spline_truc, pie_40);
line_fewer_markers(spline_truc, pie_80, 15, '-rs');
leg = legend('$\pi$ - $x_0$=.0001', '$\pi$ - $x_0$=.0002', '$\pi$ - $x_0$=.0004', '$\pi$ - $x_0$=.0008', 'location', 'best');

figure('Name', 'Reserves');
plot(spline_truc, n_10, spline_truc, n_20, spline_truc, n_40);
line_fewer_markers(spline_truc, n_80, 15, '-rs');
leg = legend('$n$ - $x_0$=.0001', '$n$ - $x_0$=.0002', '$n$ - $x_0$=.0004', '$n$ - $x_0$=.0008', 'location', 'best');
        
        
        
        
        
        
        
        